-- CALC_USER_MAX_HP

-----------------------------------------------
--  玩家最大血量
-- @param  user  玩家
return function(user)
    local max_hp = user.dbase:query("max_hp", 0);

    local combine = PropM.combine;
    local apply = PropM.apply;
    local fetchProps = PropM.fetchProps;
    local trigger = PropM.trigger;

    -- 绝对值加成最大血量
    local prop = combine(user, "attrib2", "max_hp");
    max_hp = apply(prop, max_hp);

    -- 阵营加成最大血量
    local classId = user.dbase:query("active_pet", 0)
    local campId = CampM.getPetCamp(classId)
    prop = combine(user, "camp_max_hp", campId);
    max_hp = apply(prop, max_hp);

    -- 按系别攻击加成最大血量
    local departmentId = PetM.query(classId, "department_order")[1];
    prop = combine(user, "department_max_hp", departmentId);
    max_hp = apply(prop, max_hp);

    -- 贤者之语加成
    local stoneProp = ME.user.dbase:query("stone_prop", {});
    max_hp = max_hp + (stoneProp["max_hp"] or 0);

    -- 魔藤辅助
    local bine = user.bine;
    local bineAddon = user.dbase:query("bine_addon");
    if  type(bineAddon) == "table" and bine then
        max_hp = max_hp + (bineAddon["max_hp"] or 0);
    end

    -- 机械蜘蛛辅助
    local grids = SummonM.findSummonsByClassId(53);
    if #grids > 0 then
        local grid = grids[1];
        local summon = grid.summon;
        if summon and not summon:isDead() then
            prop = PropM.combine(summon, "attrib_to_user", 1);

            local summonHp = summon:queryAttrib("max_hp") or 0;
            max_hp = max_hp + FormulaM.invoke("CALC_BIG_DIVISION", summonHp, prop[3], 1000);
        end
    end

    -- 最大生命值+,特定冈布奥效果翻倍
    local props = fetchProps(user, "slime_max_hp");
    for _, prop in ipairs(props) do
        max_hp = apply(prop, max_hp);
        if tonumber(prop[2]) == classId  then
            max_hp = apply(prop, max_hp);
        end
    end

    -- 特定地图，生命值+N
    local dungeonId = DungeonM.getDungeonId();
    local parentId = DungeonAreaM.getParentId(dungeonId);
    prop = combine(user, "dungeon_hp", parentId);
    max_hp = apply(prop, max_hp);


    -- 百分比加成最大血量
    prop = combine(user, "attrib", "max_hp");
    max_hp = apply(prop, max_hp);

    return max_hp;
end
